package po;

import java.io.Serializable;
import java.util.Calendar;

import enums.GiftType;

public class GiftPO implements Serializable {

	private static final long serialVersionUID = 1L;

	private int id;
	private Calendar beginDate;
	private Calendar endDate;
	private GiftType type;
	private double value;
	private double discount;

	public GiftPO(int id, Calendar beginDate, Calendar endDate, GiftType type,
			double value, double discount) {
		super();
		this.id = id;
		this.beginDate = beginDate;
		this.endDate = endDate;
		this.type = type;
		this.value = value;
		this.discount = discount;
	}

	public GiftPO() {
		this.type = GiftType.EQUIVALENCE;
		this.value = 0.0;
		this.discount = 1.0;
	}

	@Override
	public String toString() {
		return "GiftPO [id=" + id + ", beginDate=" + getBeginDateFormat()
				+ ", endDate=" + getEndDateFormat() + ", type=" + type
				+ ", value=" + value + ", discount=" + discount + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((beginDate == null) ? 0 : beginDate.hashCode());
		long temp;
		temp = Double.doubleToLongBits(discount);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + ((endDate == null) ? 0 : endDate.hashCode());
		result = prime * result + id;
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		temp = Double.doubleToLongBits(value);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}
	
	public int getId() {
		return id;
	}

	public Calendar getBeginDate() {
		return beginDate;
	}

	public String getBeginDateFormat() {
		return beginDate.get(Calendar.YEAR) + "-"
				+ beginDate.get(Calendar.MONTH) + 1 + "-"
				+ beginDate.get(Calendar.DATE);
	}

	public Calendar getEndDate() {
		return endDate;
	}

	public String getEndDateFormat() {
		return beginDate.get(Calendar.YEAR) + "-"
				+ beginDate.get(Calendar.MONTH) + 1 + "-"
				+ beginDate.get(Calendar.DATE);
	}

	public GiftType getType() {
		return type;
	}

	public double getValue() {
		return value;
	}

	public double getDiscount() {
		return discount;
	}

	public boolean isValid() {
		if (beginDate == null) {
			return false;
		}
		if (endDate == null) {
			return false;
		}
		Calendar today = Calendar.getInstance();
		if (today.before(beginDate)) {
			return false;
		}
		if (today.after(endDate)) {
			return false;
		}
		return true;
	}

}
